package com.ncloud.system.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.alibaba.fastjson.JSONObject;
import com.ncloud.system.entity.Dictionary;

@Mapper
public interface DictionaryMapper{

	@Select("select distinct dictionary_id, dictionary_name FROM sys_dictionary order by dictionary_id ")
	@Results({
		@Result(column="dictionary_id",property="dictionaryId"),@Result(column="dictionary_name",property="dictionaryName")})
	List<JSONObject> getDictionaryInfo();
	@Select("SELECT dictionary_id, dictionary_name, dict_key, dict_value, dict_describe, order_num, create_user,"
			+ "date_format(create_date, '%Y-%m-%d %H:%i:%s' ) as create_date, "
			+ "update_user,date_format(update_date, '%Y-%m-%d %H:%i:%s' ) as update_date, remarks FROM sys_dictionary "
			+ "where dictionary_id = #{dictionaryId} order by order_num")
	@Results({
		@Result(column="dictionary_id",property="dictionaryId"),@Result(column="dictionary_name",property="dictionaryName"),
		@Result(column="dict_key",property="dictKey"),@Result(column="dict_value",property="dictValue"),
		@Result(column="dict_describe",property="dictDescribe"),@Result(column="order_num",property="orderNum"),
		@Result(column="create_date",property="createDate"),@Result(column="update_user",property="updateUser"),
		@Result(column="update_date",property="updateDate"),@Result(column="remarks",property="remarks")})
	List<Dictionary> getDictionaryById(String dictionaryId);
	@Insert(value = "INSERT INTO sys_dictionary (dictionary_id, dictionary_name, dict_key, dict_value, dict_describe, order_num, create_user, create_date, remarks) "
			+ "values(#{dictionaryId},#{dictionaryName},#{dictKey},#{dictValue},#{dictDescribe},#{orderNum},#{createUser},#{createDate},#{remarks})")
    public int insertDictionary(Dictionary dictionary);
	
	@Update(value = "UPDATE sys_dictionary SET dictionary_name = #{dictionaryName}, dict_value = #{dictValue}, dict_describe = #{dictDescribe}, order_num = #{orderNum}, update_user = #{updateUser}, update_date = #{updateDate}, remarks = #{remarks}  "
			+ "WHERE dictionary_id = #{dictionaryId} and dict_key = #{dictKey}")
    public int updateDictionary(Dictionary dictionary);
	
	@Delete(value = "delete from sys_dictionary WHERE dictionary_id = #{0} and dict_key = #{1}")
    public int deleteDictionary(String dictionaryId,String distKey);
	@Delete(value = "delete from sys_dictionary WHERE dictionary_id = #{0}")
    public int deleteDictionaryById(String dictionaryId);
}
